package edu.towson.forensics;

import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.provider.Browser;
import android.provider.CallLog;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;

public class PhoneDBHelper {
	

	public static Uri addContacts(Context context, String accountName, String phoneNumber){
		 ContentValues values = new ContentValues();
		 values.put(RawContacts.ACCOUNT_TYPE, "com.google");
		 values.put(RawContacts.ACCOUNT_NAME, phoneNumber);
		 Uri rawContactUri = context.getContentResolver().insert(RawContacts.CONTENT_URI, values);
		 long rawContactId = ContentUris.parseId(rawContactUri);
		 //add contact name
		 values.clear();
		 values.put(Data.RAW_CONTACT_ID, rawContactId);
		 values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
		 values.put(StructuredName.DISPLAY_NAME, accountName);
		 context.getContentResolver().insert(Data.CONTENT_URI, values);
		 //add contact phone number
		 values.clear();
		 values.put(Data.RAW_CONTACT_ID, rawContactId);
		 values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
		 values.put(Phone.NUMBER, phoneNumber);
		 values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
		 values.put(Phone.LABEL, "Forensics");
		 Uri result = context.getContentResolver().insert(Data.CONTENT_URI, values);
		 return result;
	}
	
	public static Uri addCall(Context context, String number, long start) 
	{ 
//			final ContentResolver resolver = context.getContentResolver(); 
			             ContentValues values = new ContentValues(5); 
			             values.put(CallLog.Calls.NUMBER, number); 
			             values.put(CallLog.Calls.TYPE, Integer.valueOf(CallLog.Calls.INCOMING_TYPE)); 
			             values.put(CallLog.Calls.DATE, Long.valueOf(start)); 
			             values.put(CallLog.Calls.DURATION, Long.valueOf(0)); 
			             values.put(CallLog.Calls.NEW, Integer.valueOf(1)); 
			            Uri result = context.getContentResolver().insert(CallLog.Calls.CONTENT_URI, values); 
			             return result; 
			        } 
	public static Uri addBookmark(Context context, String bookmark, long start) 
	{ 
	//final ContentResolver resolver = context.getContentResolver(); 
	        ContentValues values = new ContentValues(5); 
	        values.put(Browser.BookmarkColumns.BOOKMARK, Integer.valueOf(1)); 
	        values.put(Browser.BookmarkColumns.CREATED, Long.valueOf(start)); 
	        values.put(Browser.BookmarkColumns.DATE, Long.valueOf(start)); 
	        values.put(Browser.BookmarkColumns.URL, bookmark); 
	        values.put(Browser.BookmarkColumns.TITLE, bookmark); 
	        values.put(Browser.BookmarkColumns.VISITS, Integer.valueOf(1)); 
	        Uri result = context.getContentResolver().insert(Browser.BOOKMARKS_URI, values); 
	        return result; 
	   } 
}

